import urllib3
import json



# resp1 = http.request(
#     'GET',
#     'http://localhost:8000/api/download/Dockerfile',
#     headers={
#         'path_type':'debug_path',
#         'test':'test'
#     }
# )
def fetch_file(remote_path,local_path):
    http = urllib3.PoolManager(num_pools=5)
    result = http.request(
        'GET',
        'http://localhost:8000/api/download',
        headers={
            'FILE_PATH': remote_path,
        }
    )
    with open(local_path,'wb') as file:
        file.write(result.data)
    print('over')

def fetch_file_status(remote_path):
    http = urllib3.PoolManager(num_pools=5)
    result = http.request(
        'GET',
        'http://localhost:8000/api/file_status',
        headers={
            'FILE_PATH':remote_path,
        }
    )
    status = json.loads(result.data.decode())
    return status

def fetch_folder_status(remote_path):
    http = urllib3.PoolManager(num_pools=5)
    result = http.request(
        'GET',
        'http://localhost:8000/api/folder_report',
        headers={
            'FOLDER_PATH':remote_path,
        }
    )
    print(result)
    print(result.data)
    print(result.data.decode())
    status = json.loads(result.data.decode())
    return status

def upload_file(remote_path,loal_path):
    with open(loal_path,'rb') as f:
        data = f.read()
    http = urllib3.PoolManager(num_pools=5)
    result = http.request(
        'POST',
        'http://localhost:8000/api/upload_file',
        headers={
            'FILE_PATH':remote_path
        },
        data=data
    )
    print(result.data)

# res = fetch_folder_status('d:\\test')
upload_file('d:\\test\\SteamSetup1.exe','d:\\test\\SteamSetup.exe')

# fetch_file('C:\\Users\\yuang\\untitled.md','C:\\Users\\yuang\\test.md')
# status = fetch_file_status('C:\\Users\\yuang\\test.md')


